package protocol.JT808_2011;

import java.util.HashMap;

public class Handle808_2011JT88 implements IHandle808_2011JT {
    @Override
    public String handle(JT808_2011Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle8800(cmd);
            case 0x01:
                return handle8801(cmd);
            case 0x02:
                return handle8802(cmd);
            case 0x03:
                return handle8803(cmd);
            case 0x04:
                return handle8804(cmd);
            default:
                return "808-2011:未匹配的命令字"+(cmd.readOrder());
        }
    }

    private String handle8804(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:录音开始命令");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"停止");
        list.put(1,"开始");
        int type = cmd.readInt();

        builder.append("录音命令("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("录音时间（0表示一直录音）："+cmd.readWORD());
        builder.append("\r\n");

        list.clear();
        list.put(0,"实时上传");
        list.put(1,"保存");
        type = cmd.readInt();

        builder.append("保存标识("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"8k");
        list.put(1,"11k");
        list.put(2,"23k");
        list.put(3,"32k");
        type = cmd.readInt();

        builder.append("音频采样率("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8803(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:存储多媒体数据上传命令");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"图像");
        list.put(1,"音频");
        list.put(2,"视频");
        int type = cmd.readInt();

        builder.append("多媒体类型("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("通道ID(0表示检索全部摄像头):"+cmd.readInt(1));
        builder.append("\r\n");

        list.clear();
        list.put(0,"平台下发指令");
        list.put(1,"定时动作");
        list.put(2,"抢劫报警触发");
        list.put(3,"碰撞侧翻报警触发");

        type = cmd.readInt();
        builder.append("事件项编码("+type+"："+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("起始时间："+cmd.readBCD(6));
        builder.append("\r\n");
        builder.append("结束时间："+cmd.readBCD(6));
        builder.append("\r\n");

        list.clear();
        list.put(0,"保留");
        list.put(1,"删除");

        type = cmd.readInt();
        builder.append("删除标识("+type+"："+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8802(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:存储多媒体数据检索");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"图像");
        list.put(1,"音频");
        list.put(2,"视频");
        int type = cmd.readInt();

        builder.append("多媒体类型("+type+"):"+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("摄像头ID(0表示检索全部摄像头):"+cmd.readInt(1));
        builder.append("\r\n");

        list.clear();
        list.put(0,"平台下发指令");
        list.put(1,"定时动作");
        list.put(2,"抢劫报警触发");
        list.put(3,"碰撞侧翻报警触发");

        type = cmd.readInt();
        builder.append("事件项编码("+type+"："+list.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        builder.append("起始时间："+cmd.readBCD(6));
        builder.append("\r\n");
        builder.append("结束时间："+cmd.readBCD(6));
        builder.append("\r\n");
        return builder.toString();
    }
    private String handle8801(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:摄像头立即拍摄命令");
        builder.append("\r\n");
        HashMap<Integer,String> list = new HashMap<>();
        builder.append("摄像头ID:"+cmd.readInt(1));
        builder.append("\r\n");

        builder.append("拍摄张数（0为停止拍摄,65535为录像）:"+cmd.readWORD());
        builder.append("\r\n");

        builder.append("拍照间隔/录像时间（0表示按最小拍照间隔或一直录像）:"+cmd.readInt(2));
        builder.append("\r\n");

        list.put(0,"实时上传");
        list.put(1,"保存");
        builder.append("保存标志:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"最低分辨率");
        list.put(1,"320*240");
        list.put(2,"640*480");
        list.put(3,"800*600");
        list.put(4,"1024*768");
        list.put(5,"176*144(QCIF)");
        list.put(6,"352*288(CIF)");
        list.put(7,"704*288(HALF D1)");
        list.put(8,"704*576(D1)");

        builder.append("分辨率:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("图像/视频质量（1～10，1最好）:"+cmd.readInt(1));
        builder.append("\r\n");

        builder.append("亮度（0～255）:"+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("对比度（0～127）:"+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("饱和度（0～127）:"+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("色度（0～255）:"+cmd.readInt(1));
        builder.append("\r\n");


        return builder.toString();
    }

    private String handle8800(JT808_2011Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:多媒体数据上传应答");
        builder.append("\r\n");
        builder.append("多媒体ID:"+cmd.readDWORD());
        builder.append("\r\n");
        int size = cmd.readInt();
        builder.append("重传总包数:"+size);
        builder.append("\r\n");

        for (int i = 0; i < size; i++) {
            builder.append("重传ID:"+cmd.readDWORD());
            builder.append("\r\n");
        }

        return builder.toString();
    }
}
